import React,{useState} from 'react'

export default function UseStateDemo() {

  console.log("UseStateDemo");
  
  //  定义状态
  const [age,setAge] = useState(12);

  function changeAge(){    
    setAge(age+1);
  }

  const [person,setPerson] = useState({
    name:"柴正盼",
    height:180
  })

  function changeHeight(){
    setPerson({
      ...person,
      height:person.height+1
    });
  }
    
  return (
    <>
      <div>useState</div>
      <p>age:{age}</p>
      <input type="button" value="修改age" onClick={changeAge} />

      <hr/>
      <p>person.name:{person.name}</p>
      <p>person.height:{person.height}</p>
      <input type="button" value="长高" onClick={changeHeight} />    
    </>
  )
}